﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ContinuousMacro.CApCMContinuousMacroProjectionDisplayer
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.DataTypes.Graphics;


namespace DnProcessSimulateCommands.ContinuousMacro;

internal class CApCMContinuousMacroProjectionDisplayer : 
  CApCMGraphicsShapeDisplayer<ITxDisplayableObject>
{
  private bool isNonEmpty;
  private TxObjectList componentsList;

  public CApCMContinuousMacroProjectionDisplayer(
    TxRoboticViaLocationOperation viaLocation,
    TxComponent displayParent,
    ITxDisplayableObject continuousMacro,
    ITxLocatableObject projectionComponent)
    : base(viaLocation, displayParent, continuousMacro, projectionComponent)
  {
    this.IsRecreatedOnAbsoluteLocationChanged = true;
  }

  public bool IsNonEmpty
  {
    get => this.isNonEmpty;
    private set
    {
      if (this.isNonEmpty == value)
        return;
      this.isNonEmpty = value;
      if (this.IsNonEmptyChanged == null)
        return;
      this.IsNonEmptyChanged();
    }
  }

  public static bool IsProjectionCutThrough { get; set; }

  public static bool IsProjectionFlippped { get; set; }

  public event Action IsNonEmptyChanged;

  protected override ITxDisplayableObject CreateShape()
  {
    if (this.componentsList == null)
      this.componentsList = (this.DependencyObject as ITxObjectCollection).GetComponents();
    TxObjectList<ITxDisplayableObject> entities = new TxObjectList<ITxDisplayableObject>();
    foreach (ITxObject components in (Collection<ITxObject>) this.componentsList)
    {
      try
      {
        TxVector txVector = new TxVector(this.ViaLocation.AbsoluteLocation[0, 2], this.ViaLocation.AbsoluteLocation[1, 2], this.ViaLocation.AbsoluteLocation[2, 2]);
        if (CApCMContinuousMacroProjectionDisplayer.IsProjectionFlippped)
          txVector = TxVector.op_UnaryNegation(txVector);
        TxCurveProjectionOnUnTrimmedBodyCreationData bodyCreationData = new TxCurveProjectionOnUnTrimmedBodyCreationData(this.CreationData as ITx1Dimensional, components as ITxComponent, txVector, CApCMContinuousMacroProjectionDisplayer.IsProjectionCutThrough);
        bodyCreationData.SetAsDisplay();
        foreach (ITx1Dimensional itx1Dimensional in (Collection<ITx1Dimensional>) TxComponentEx.CreateCurveByProjectionOnUnTrimmedBody((ITxGeometryCreation) this.DisplayParent, bodyCreationData))
        {
          ITxDisplayableObject displayableObject = itx1Dimensional as ITxDisplayableObject;
          displayableObject.Color = TxColor.FromBgrColor(TxApplication.Options.Color.SolidColor);
          TxDisplayableObjectEx.SetSelectable(displayableObject, false);
          ((Collection<ITxDisplayableObject>) entities).Add(displayableObject);
        }
      }
      catch (Exception ex)
      {
      }
    }
    this.IsNonEmpty = ((Collection<ITxDisplayableObject>) entities).Count > 0;
    return (ITxDisplayableObject) new CApCMContinuousMacroProjectionDisplayer.CompositeDisplayableObject((Collection<ITxDisplayableObject>) entities);
  }

  private class CompositeDisplayableObject : ITxDisplayableObject, ITxObject
  {
    private Collection<ITxDisplayableObject> entities;

    public CompositeDisplayableObject(Collection<ITxDisplayableObject> entities)
    {
      this.entities = entities;
    }

    public void Delete()
    {
      foreach (ITxObject entity in this.entities)
        entity.Delete();
    }

    public void Blank()
    {
      foreach (ITxDisplayableObject entity in this.entities)
        entity.Blank();
    }

    public void Display()
    {
      foreach (ITxDisplayableObject entity in this.entities)
        entity.Display();
    }

    public TxColor Color
    {
      get => throw new NotImplementedException();
      set => throw new NotImplementedException();
    }

    public HashSet<TxColor> GetColors() => throw new NotImplementedException();

    public double Transparency
    {
      get => throw new NotImplementedException();
      set => throw new NotImplementedException();
    }

    public TxDisplayMode DisplayMode
    {
      set => throw new NotImplementedException();
    }

    public TxEmphasizeColor SelfEmphasizedColor => throw new NotImplementedException();

    public void RestoreColor() => throw new NotImplementedException();

    public TxDisplayableObjectVisibility Visibility => throw new NotImplementedException();

    public event TxDisplayableObject_VisibilitySetEventHandler VisibilitySet;

    public event TxDisplayableObject_EmphasizedEventHandler Emphasized;

    public event TxDisplayableObject_EmphasizeStoppedEventHandler EmphasizeStopped;

    public ArrayList Attributes => throw new NotImplementedException();

    public bool CanBeDeleted => throw new NotImplementedException();

    public bool CanBeModified => throw new NotImplementedException();

    public bool CanBeRenamed => throw new NotImplementedException();

    public ITxObjectCollection Collection => throw new NotImplementedException();

    public event TxObject_CopiedEventHandler Copied;

    internal event TxObject_AttributeModifiedEventHandler AttributeModified;

    public event TxObject_DeletedEventHandler Deleted;

    public TxAttribute GetAttribute(string attributeName) => throw new NotImplementedException();

    public string Id => throw new NotImplementedException();

    public bool IsTransient => throw new NotImplementedException();

    public bool IsValid() => throw new NotImplementedException();

    public string Name
    {
      get => throw new NotImplementedException();
      set => throw new NotImplementedException();
    }

    public event TxObject_NameChangedEventHandler NameChanged;

    public void RemoveAttribute(string attributeName) => throw new NotImplementedException();

    public void SetAttribute(TxAttribute attribute) => throw new NotImplementedException();

    public event TxObject_IsTransientChangedEventHandler IsTransientChanged;

    Type ITxObject.GetType() => this.GetType();
  }
}
